﻿myApp.controller('NewsDetailController', function ($scope, $http, $routeParams, $filter, NgMap, $location,$rootScope) {
    $scope.isSearch = true;
    $scope.isAndroid = $rootScope.isAndroid;
    //$scope.share = {};

    $scope.submitForm = function (obj) {
        var url = 'https://script.google.com/macros/s/AKfycbwcomu5o2CIbkO1lCjyZhDrF_dejSPWi0VAj9knYKYRr3jHDUY/exec';
        $http({
            method: 'POST',
            url: url,
            data: $(obj.target).serialize(),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        }).success(function (data) {
            alert("Thanks for Subscribing to our Newsletter!");
            $scope.subscription_email = "";
        });
    }

    $scope.current_path_url = $location.absUrl();



    var BASE_URL;
    if ($location.host() == "localhost") {
        BASE_URL = $location.protocol() + "://" + "localhost:" + $location.port();
    } else {
        BASE_URL = $location.protocol() + "://" + $location.host();
    }





    pageInit();
    function pageInit(){ 
        var url = 'api/News/GetNew/' + $routeParams.id;
        $http.get(url).success(function (data) {
            console.log("NEWS DETAIL: " + JSON.stringify(data));
            $scope.News = data.MobileNews;
            $scope.NewPhoto = data.pictureList[0].pictureURL;

            $scope.NewsDetails = data.MobileNews.Details.replace(new RegExp('\r?\n', 'g'), '<br />');


            // alert(data.pictureList[0].pictureURL);
            $scope.News.CreateDate = new Date($scope.News.CreateDate);
            $scope.slides = data.pictureList;


            $scope.shareTitle = data.MobileNews.Title;
            $scope.shareDescription = data.MobileNews.Details;
            $scope.shareURL = BASE_URL + "/info/news/details/" + $routeParams.id;
            $scope.shareImageURL = data.pictureList[0].pictureURL || "http://www.penangrealty.my/images/penang realty,Apartment,house,condominium,terrace house,semi d,detached,bungalow,high end luxury properties,landed properties,gated guarded house.png";

            $scope.googleShareURL = encodeURI(encodeURI($scope.shareURL));
            $scope.isSearch = false;



            //        $scope.share.url = 'http://www.penangrealty.my/NewDetail/' + $routeParams.id.toString();
            //        $scope.share.pictureUrl = $scope.slides ? $scope.slides[0].pictureURL : 'http://www.penangrealty.my/images/penang realty,Apartment,house,condominium,terrace house,semi d,detached,bungalow,high end luxury properties,landed properties,gated guarded house.png';
            //        $scope.share.description = "[" + $scope.News.Title + '] ' + $scope.News.Source + " - " + $scope.News.CreateDate
            //+ '\n' + $scope.News.Details + '\n' + window.location.href + '\n';
            //        //+ "Contact: " + $scope.property.mobile + " (" + $scope.property.agentname + ")";
            //        document.title = "Penang Realty 世界地產 " + $scope.News.Title;
            //        $scope.$emit('newPageLoaded', { 'title': $scope.News.Title, 'description': $scope.News.Details });
        }).success(function (err) {
            // alert(JSON.stringify(err));
            $scope.isSearch = false;

        });
          
    }



});